package dbtools.structures;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.TreeMap;

public abstract class DBTable implements Serializable{
	private static final long serialVersionUID = 1L;
	
	/**
	 * Ascending
	 */
	protected static final boolean ASC = true;
	
	/**
	 * Descending
	 */
	protected static final boolean DESC = false;
	
	private ArrayList<DBField> myFields = new ArrayList<DBField>();
	private TreeMap<String, DBField> myFieldsByName = new TreeMap<String, DBField>();

	private ArrayList<DBUniqueKey> myKeys = new ArrayList<DBUniqueKey>();

	public abstract String getTableName();

	public void addField(DBField fld) {
		myFields.add(fld);
		myFieldsByName.put(fld.getName(), fld);
	}
	
	public DBField[] getAllFields(){
		return myFields.toArray(new DBField[0]);
	}

	public void addKey(DBUniqueKey key) {
		myKeys.add(key);
	}
	
	public DBUniqueKey[] getAllKeys(){
		return myKeys.toArray(new DBUniqueKey[0]);
	}

	public DBField getFieldByName(String name) {
		return myFieldsByName.get(name);
	}
}
